#ifndef WEBSERVER_H
#define WEBSERVER_H

#include <QObject>
#include <qhttpserver.h>
#include <qhttprequest.h>
#include <qhttpresponse.h>
#include "db/db.h"
#include "entity/trcoleta.h"

class WebServer : public QObject
{
    Q_OBJECT
public:
    explicit WebServer(QObject *parent = 0, int port = 8080);

    bool started();

private:

    void handleGet(QHttpRequest *req, QHttpResponse *resp);
    void handleGetPesagensInfo(QHttpRequest *req, QHttpResponse *resp);

    void handleDelete(QHttpRequest *req, QHttpResponse *resp);

    bool importColetaToBD();
    bool importColetaItemsToBD(TRCOLETA *coleta, qulonglong originalId);
    bool importColeta();
    bool checkMD5AndSave(const QByteArray &data, QString fname);
    bool checkFilesMD5(const QByteArray &MD5Data);

    void sendResponseFile(QHttpResponse *resp, QString fname);

    bool updateFornPos(QHttpRequest *req);

    DB *db;
    bool _started;
signals:

private slots:
    void handleRequest(QHttpRequest *req, QHttpResponse *resp);

    void handlePost(QHttpRequest *req, QHttpResponse *resp);
};

#endif // WEBSERVER_H
